package jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 创建一张表article
 * 表结构
 *  id 整数类型，主键，自增           唯一标识
 *  title 字符串类型，长度200个字符     文章标题
 *  content 字符串类型，长度1000个字符  文章正文
 */
public class Test2 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();){
            /*
                CREATE TABLE article(
                    id INT PRIMARY KEY AUTO_INCREMENT,
                    title VARCHAR(200),
                    content VARCHAR(1000)
                )
             */
            String sql = "CREATE TABLE article( " +
                         "  id INT PRIMARY KEY AUTO_INCREMENT, " +
                         "  title VARCHAR(200), " +
                         "  content VARCHAR(1000) " +
                         ")";
            //Statement用于执行静态SQL(不含用户输入的信息)
            Statement statement = connection.createStatement();
            statement.execute(sql);
            System.out.println("表创建完毕");
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}






